package com.andaily.web.controller.validator;

import com.andaily.domain.dto.account.AccountTypeDTO;
import org.apache.commons.lang.StringUtils;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
 * @author Shengzhao Li
 */
public class AccountTypeFormValidator implements Validator {
    @Override
    public boolean supports(Class<?> clazz) {
        return clazz.equals(AccountTypeDTO.class);
    }

    @Override
    public void validate(Object target, Errors errors) {
        AccountTypeDTO accountType = (AccountTypeDTO) target;

        String name = accountType.getName();
        if (StringUtils.isEmpty(name)) {
            errors.rejectValue("name", null, "名称不能为空");
        }

    }


}
